
<script language='javascript'>
    var winForm, winSendMessage, winSendMessageGroup;
    var threadsManager, intervalIdManager, _wallIdSelected, _pingTime = 5000;
    var _rp = 2, _rpUsers = 12;
    var _postArrayManager, _paginatorManager, _paginatorUserManager;
    var i=0;
    
    $(document).ready(function() {
        
        var imagePathEmail = BASE_ICONS+'email.png';
        var imageJuanelo = BASE_PATH+'images/juanelo.png';
        
        threadsManager = new Array();
        intervalIdManager = new Array();
        _postArrayManager = new Array();
        _paginatorManager = new Array();
        _paginatorUserManager = new Array();
        
        function _paginateMembers(page, groupId){
            Rocket.Request({
                url: BASE_URL + 'rols/paginateMembers',
                data:{
                    page:page,
                    rp:_rpUsers,
                    groupId:groupId
                },
                success:function(response) {
                    var panelMembersId = "panelMembers_"+groupId;
                    var panel = Rocket.get(panelMembersId);
                    var members = response.data.items;
                    var memberHtml = "";
                    jQuery.each(members,function(k,member){
                        var uid = groupId+"_"+member.UserId;
                        var nombre = member.nombre1+' '+member.apellido1;
//                        var nombre = member.nombre1+' '+member.nombre2+
//                            ' '+member.apellido1+' '+member.apellido2;
                        //console.debug(member.avatar);
                        if(!member.avatar || member.avatar === 'null' || member.avatar === null) 
                            member.avatar = imageJuanelo;
                        
                        
                        memberHtml = memberHtml+
                            '<div class="member">'+
                            '<img class="member_avatar" src="'+member.avatar+'"/>'+
                            '<ul>'+
                            '<li class="member_name"><a href="#" id="'+uid+'">'+nombre+'</a></li>'+
                            '<li class="member_rol">'+member.nombre+'</li>'+
                            '</ul>'+
                            '<div style="margin-top:-19px;margin-left:-5px;" class="member_actions">'+
                            '<a href="#" id="email-'+uid+'"><img src="'+imagePathEmail+'" width="16"/></a>'+
                            '</div>'+
                            '</div>';

                        //seteamos la funcion click en cada nombre de usario con live aun cuando no exista en el DOM
                        jQuery('#'+uid).live('click',function(){
                            var record = new Model(member);
                            userDetail(record);
                        });

                        //seteamos la funcion click en cada email de usario con live aun cuando no exista en el DOM
                        jQuery('#email-'+uid).live('click',function(){
                            _sendMessageToUser(member);
                        });


                    });
                    panel.setHtml('<div class="members">'+memberHtml+'</div>');
                }
            });
        }
        
        function _addPaginator4UsersByGroup(groupId,total){
            if(!_paginatorUserManager[groupId]){
                var total = total;
                var page = 2;//consideramos de que ya se ha cargado la pagina 1
                var paginatorId = "#paginatorMembers_"+groupId;
                var nPages=0;
                if(total%_rpUsers === 0){
                    nPages = total/_rpUsers;
                }
                else{
                    if(total<_rpUsers)
                        nPages = 1;
                    else{
                        nPages = parseInt(total/_rpUsers)+1;
                    }
                }
                var paginator = '<div class="pagination" id="'+paginatorId+'">'+
                    '<a href="#" class="first" data-action="first">&laquo;</a>'+
                    '<a href="#" class="previous" data-action="previous">&lsaquo;</a>'+
                    '<input type="text" readonly="readonly" data-max-page="'+nPages+'" />'+
                    '<a href="#" class="next" data-action="next">&rsaquo;</a>'+
                    '<a href="#" class="last" data-action="last">&raquo;</a>'+
                    '</div>';
            
                jQuery(paginatorId).append(paginator);
            
                $(paginatorId).jqPagination({
                    paged: function(page) {
                        _paginateMembers(page, groupId);
                    }
                });
                _paginatorUserManager[groupId] = nPages;
            }
        }
        
        function userDetail(record){
            var resAjax = true;//aqui llamamos al usuario con sus datos
            Rocket.Request({
                url: BASE_URL + 'users/det_user',
                data:{
                    userId : record.get('UserId'),
                    user_name : record.get('nombre1')+' '+record.get('apellido1')},
                success:function(data) {
                    if (data.success){
                        displayUserData(data);          
                    }
                    else{

                        Rocket.Create({
                            type:'dialog',
                            title:'Error en la operacion',
                            typeAlert:'error',
                            message:_getErrorFromArray(data.errors)
                        });
                    }
                }
            });
            if(resAjax){
                jQuery('#liNombre').text(record.get('nombre1')+' '+record.get('nombre2')+' '+record.get('apellido1')+' '+record.get('apellido2'));
                jQuery('#liRut').text(record.get('rut'));
                jQuery('#liFechaNacimiento').text(record.get('fechanacimiento'));
                jQuery('#imgAvatar').attr('src',imageJuanelo);
                winDetail.show();
            }
        }
        
        function _getGroups(){
            Rocket.Request({
                url: BASE_URL + 'grupos/getGroups',
                data:{
                    type:'discipulo',
                    rp_members:_rpUsers
                },
                success:function(response) {
                    _setUsersData(response.data);
                }
            });
        }
        function _addPaginator(groupId,total){
            if(!_paginatorManager[groupId]){
                var total = total;
                var page = 2;//consideramos de que ya se ha cargado la pagina 1
                var paginatorId = "#paginatorForo_"+groupId;
                var nPages=0;
                
                if(total%_rp === 0){
                    nPages = total/_rp;
                }
                else{
                    if(total<_rp)
                        nPages = 1;
                    else{
                        nPages = parseInt(total/_rp)+1;
                    }
                }
                var moreMessages = total-_rp;
                var _moreTmp = moreMessages;
                var rpAux = 0;
                if(moreMessages>0){
                    jQuery(paginatorId).append("<li><a rpAux='"+rpAux+"' page='"+page+"' id='moreMessages_"+groupId+"' href='javascript:void(0);'>Ver comentarios anteriores "+moreMessages+"</a></li>");
                    jQuery("#moreMessages_"+groupId).click(function(){
                        var newPage = jQuery(this).attr('page');
                        var rpAux = parseInt(jQuery(this).attr('rpAux'));
                        threadsManager[groupId].stop();
                        threadsManager[groupId].loadPage(newPage);
                        newPage++;
                        jQuery(this).attr('page',newPage);
                        if(rpAux>=0){
                            rpAux = rpAux+_rp;
                            if(rpAux<_moreTmp){
                                jQuery(this).text('Ver comentarios anteriores '+rpAux+" de "+_moreTmp);
                                jQuery(this).attr('rpAux',rpAux);
                            }
                            else{
                                jQuery(this).text('');
                                rpAux = -1;
                            }
                        }
                        else    jQuery(this).text('');
                    });
                }
                _paginatorManager[groupId] = nPages;
            }
        }
        function _refreshWall(data, groupId, typeAppend){
            var foro = "#messagesForo_"+groupId+"_wall";
            var messagesForoId = "messagesForo_"+groupId;
            var posts = data.rows;
            
            _addPaginator(groupId,data.total)
            if(!typeAppend) var posts = data.rows.reverse();
            
            jQuery.each(posts, function(i,post){
                var nombre = post.nombre1+" "+post.nombre2+" "+post.apellido1+" "+post.apellido2;
                var date = Rocket.parseDateString(post.Created);
                //solo si el post no ha sido cargado lo metemos
                if(!_postArrayManager[post.PostId]){
                    _postArrayManager[post.PostId] = post;
                    var html =  "<li>"+
                        "<img src='"+post.avatar+"'/>"+
                        "<ul>"+
                        "<li class='message_detail'>"+
                        "<span>"+nombre+"</span>"+post.Message+
                        "</li>"+
                        "<li class='message_detail'> El <label>"+date.day+"</label> de "+
                        "<label>"+date.month+"</label>"+
                        " a las <label>"+date.hour+":"+date.minute+"</label>"+
                        "</li>"+
                        "<ul>"+
                        "</li>";
                    if(typeAppend && typeAppend === 'prepend'){
                        jQuery(foro).prepend(html);
                    }
                    else{
                        jQuery(foro).append(html);
                    }
                    
                }
            });
        }
        
        function displayUserData(data){
            jQuery('#imgAvatar').attr('src',data.data.DATA[0]['avatar']);
            jQuery('#liRut').text(data.data.DATA[0]['rut']);
            jQuery('#liNombre').text(data.data.DATA[0]['nombre1']+' '+data.data.DATA[0]['nombre2']+' '+data.data.DATA[0]['apellido1']+' '+data.data.DATA[0]['apellido2']);
            jQuery('#liFechaNacimiento').text(data.data.DATA[0]['fechanacimiento']);
            jQuery('#liEmail').text(data.data.DATA[0]['email']);
            jQuery('#liSexo').text(data.data.DATA[0]['sexo']);
            jQuery('#liFonoMovil').text(data.data.DATA[0]['fono_movil']);
            jQuery('#liFonoFijo').text(data.data.DATA[0]['fono_fijo']);
            jQuery('#liDireccion').text(data.data.DATA[0]['direccion']);
            jQuery('#liOficio').text(' '+data.data.OFICIO);
            
            jQuery('#LiEncuentros').children("li").remove();
            for (var x = 1;x<=data.data.GROUPS.length;x++){
                if(data.data.GROUPS[x-1]['disp'] == 'Y') jQuery('#LiEncuentros').append('<li><label>'+data.data.GROUPS[x-1]['name']+': </label><div id="liPreEncuentro" class="rck-icon-tick"></div></li>');
                else jQuery('#LiEncuentros').append('<li><label>'+data.data.GROUPS[x-1]['name']+': </label><div id="liPreEncuentro" class="rck-icon-none"></div></li>');
            }
            jQuery('#ulCurrents').children("li").remove();
            for (var x = data.data.GEN.length;x>=1;x--){
                jQuery('#ulCurrents').append('<li>'+data.data.GEN[x-1]['user_name']+'</li>');    
                if(x>1) jQuery('#ulCurrents').append('<li class="arrow"></li>');
            }
            
            jQuery('#ulCurrentp').children("li").remove();
            jQuery('#ulCurrentp').children("ul").remove();
            jQuery('#ulCurrentp').children("label").remove();
            jQuery('#ulCurrentp').children("strong").remove();
            
            //console.debug(data.data.T[0]['group_data'][0]['leader_data'].length);
            for (var x = 1;x<=data.data.T.length;x++){
                jQuery('#ulCurrentp').append('<li>');
                jQuery('#ulCurrentp').append('<label><strong>'+data.data.T[x-1]['nombrerol']+'</strong> de <a href="javascript:void(0);" class="lnkActivity">'+data.data.T[x-1]['nombre']+'</a></label>'); 
                jQuery('#ulCurrentp').append('<ul>');
                jQuery('#ulCurrentp').append('<li>Direccion : '+data.data.T[x-1]['group_data'][0]['direccion']+'</li>');
                jQuery('#ulCurrentp').append('<li>Reunion : '+data.data.T[x-1]['group_data'][0]['dia_reunion']+' '+data.data.T[x-1]['group_data'][0]['hora_reunion']+'</li>');
                jQuery('#ulCurrentp').append('<li>Iglesia : '+data.data.T[x-1]['group_data'][0]['nombre']+'</li>');
                if(data.data.T[x-1]['group_data'][0]['leader_data'].length >0){
                    jQuery('#ulCurrentp').append('<li>Lider : '+data.data.T[x-1]['group_data'][0]['leader_data'][0]['username']+'</li>');
                    jQuery('#ulCurrentp').append('<li>Email Lider : '+data.data.T[x-1]['group_data'][0]['leader_data'][0]['email']+'</li>');
                    jQuery('#ulCurrentp').append('<li>Telefonos : '+data.data.T[x-1]['group_data'][0]['leader_data'][0]['fono']+'</li>');
                }
                jQuery('#ulCurrentp').append('</ul>');
                jQuery('#ulCurrentp').append('</li>');
            }
            
            jQuery('#ulCurrentf').children("li").remove();
            jQuery('#ulCurrentf').children("ul").remove();
            jQuery('#ulCurrentf').children("label").remove();
            jQuery('#ulCurrentf').children("strong").remove();
            for (var x = 1;x<=data.data.F.length;x++){
                jQuery('#ulCurrentf').append('<li>');
                jQuery('#ulCurrentf').append('<label><strong>'+data.data.F[x-1]['nombrerol']+'</strong> de <a href="javascript:void(0);" class="lnkActivity">'+data.data.F[x-1]['nombre']+'</a></label>'); 
                jQuery('#ulCurrentf').append('<ul>');
                jQuery('#ulCurrentf').append('<li>Direccion : '+data.data.F[x-1]['group_data'][0]['direccion']+'</li>');
                jQuery('#ulCurrentf').append('<li>Reunion : '+data.data.F[x-1]['group_data'][0]['dia_reunion']+' '+data.data.F[x-1]['group_data'][0]['hora_reunion']+'</li>');
                jQuery('#ulCurrentf').append('<li>Iglesia : '+data.data.F[x-1]['group_data'][0]['nombre']+'</li>');
                if(data.data.F[x-1]['group_data'][0]['leader_data'].length >0){
                    jQuery('#ulCurrentf').append('<li>Lider : '+data.data.F[x-1]['group_data'][0]['leader_data'][0]['username']+'</li>');
                    jQuery('#ulCurrentf').append('<li>Email Lider : '+data.data.F[x-1]['group_data'][0]['leader_data'][0]['email']+'</li>');
                    jQuery('#ulCurrentf').append('<li>Telefonos : '+data.data.F[x-1]['group_data'][0]['leader_data'][0]['fono']+'</li>');
                }
                jQuery('#ulCurrentf').append('</ul>');
                jQuery('#ulCurrentf').append('</li>');
            }
            
            jQuery('#ulCurrentPast').children("li").remove();
            jQuery('#ulCurrentPast').children("ul").remove();
            jQuery('#ulCurrentPast').children("label").remove();
            jQuery('#ulCurrentPast').children("strong").remove();
            for (var x = 1;x<=data.data.P.length;x++){
                jQuery('#ulCurrentPast').append('<li>');
                jQuery('#ulCurrentPast').append('<label><strong>'+data.data.P[x-1]['nombrerol']+'</strong> de <a href="javascript:void(0);" class="lnkActivity">'+data.data.P[x-1]['nombre']+'</a></label>'); 
                jQuery('#ulCurrentPast').append('<ul>');
                jQuery('#ulCurrentPast').append('<li>Direccion : '+data.data.P[x-1]['group_data'][0]['direccion']+'</li>');
                jQuery('#ulCurrentPast').append('<li>Reunion : '+data.data.P[x-1]['group_data'][0]['dia_reunion']+' '+data.data.P[x-1]['group_data'][0]['hora_reunion']+'</li>'); 
                jQuery('#ulCurrentPast').append('<li>Iglesia : '+data.data.P[x-1]['group_data'][0]['nombre']+'</li>');
                if(data.data.P[x-1]['group_data'][0]['leader_data'].length >0){
                    jQuery('#ulCurrentPast').append('<li>Lider : '+data.data.P[x-1]['group_data'][0]['leader_data'][0]['username']+'</li>');
                    jQuery('#ulCurrentPast').append('<li>Email Lider : '+data.data.P[x-1]['group_data'][0]['leader_data'][0]['email']+'</li>');
                    jQuery('#ulCurrentPast').append('<li>Telefonos : '+data.data.P[x-1]['group_data'][0]['leader_data'][0]['fono']+'</li>');
                }
                jQuery('#ulCurrentPast').append('</ul>');
                jQuery('#ulCurrentPast').append('</li>');
            }
            
            
        }
      
        function _setUsersData(data){
            var members = '';
            var grupos = new Array();
            var bodyStyleGroup = "width:94.7%;*width:94.7%;_width:94.7%;#width:94.7%;float:left;";
            var styleGroup = "float:left;margin-right:50px;";
            var width = "45%";
            var height = 490;
            var collapsible = true;
            var collapsed = true;
            
            jQuery.each(data, function(i,group){
                var title = group.tipo+" "+group.nombre;
                var gid =  Rocket.uniqueId()+"-"+group.GrupoId;
                
                var li_id = "li_"+group.GrupoId;
                var panelId = "panel_"+group.GrupoId;
                var panelActionsId = "panelActions_"+group.GrupoId;
                var btnNewUserId = "btnNewUser_"+group.GrupoId;
                var btnSendMsgId = "btnSendMsg_"+group.GrupoId;
                
                var panelMembersId = "panelMembers_"+group.GrupoId;
                
                var bigPanelMembersId = "bigPanelMembersId_"+group.GrupoId;
                var membersPaginator = "membersPaginator_"+group.GrupoId;
                
                var panelForoId = "panelForo_"+group.GrupoId;
                var txtForoId = "txtForo_"+group.GrupoId;
                var btnForoId = "btnForo_"+group.GrupoId;
                var messagesForoId = "messagesForo_"+group.GrupoId;
                
                var paginatorId = "paginatorForo_"+group.GrupoId;
                var paginatorMembersId = "paginatorMembers_"+group.GrupoId;
                
                var members = group.Members;
                
                jQuery(".ul_page").append('<li style="padding-top:10px;" id="'+li_id+'"></li>');
                
                threadsManager[group.GrupoId] = {
                    postAdded:false,
                    start:function(cleanAndRestart){
                        if(!cleanAndRestart){
                            intervalIdManager[group.GrupoId] = setInterval(function(){
                                Rocket.Request({
                                    url: BASE_URL + 'posts/getNews',
                                    data:{
                                        WallId:group.WallId,
                                        GrupoId:group.GrupoId,
                                        Page:1,
                                        Rp:_rp
                                    },
                                    success:function(response) {
                                        if(threadsManager[group.GrupoId].postAdded)
                                                typeAppend = 'prepend';
                                        else    typeAppend = 'append';
                                        _refreshWall(response, group.GrupoId,typeAppend);
                                    }
                                });
                            },_pingTime);
                        }
                        else{
                            Rocket.Request({
                                url: BASE_URL + 'posts/getNews',
                                data:{
                                    WallId:group.WallId,
                                    GrupoId:group.GrupoId,
                                    Page:1,
                                    Rp:_rp
                                },
                                success:function(response) {
                                    _refreshWall(response, group.GrupoId,'prepend');
                                    threadsManager[group.GrupoId].start();
                                }
                            });
                        }
                    },
                    stop:function(){
                        clearInterval(intervalIdManager[group.GrupoId])
                    },
                    loadPage:function(page){
                        var typeAppend = "append";
                        Rocket.Request({
                            url: BASE_URL + 'posts/getNews',
                            data:{
                                WallId:group.WallId,
                                GrupoId:group.GrupoId,
                                Page:page,
                                Rp:_rp
                            },
                            success:function(response) {
                                _refreshWall(response, group.GrupoId, typeAppend);
                                threadsManager[group.GrupoId].start();
                            }
                        });
                    }
                };
                grupos.push(Rocket.Create(
                {
                    type:'panel',
                    id:panelId,
                    title:title,
                    height:'200px',
                    collapsible:collapsible,
                    collapsed:true,
                    renderTo:li_id,
                    bodyStyle:'float:left;width:97.2%;',
                    onCollapsing:function(Element,collapsed){
                        _wallIdSelected = group.WallId;
                        if(!collapsed){
                            //threadsManager[group.GrupoId].start();
                            threadsManager[group.GrupoId].stop();
                            threadsManager[group.GrupoId].loadPage(1);
                        }
                        else{
                            threadsManager[group.GrupoId].stop();
                        }
                    },
                    items:[
                        {
                            type:'panel',
                            id:panelActionsId,
                            width:'100%',
                            height:100,
                            style:'float:left;',
                            bodyStyle:'width:96.7%;*width:94.7%;_width:94.7%;#width:94.7%;float:left;',
                            items:[
                                {
                                    type:'button',
                                    id:btnSendMsgId,
                                    width:'220px',
                                    value:'Enviar mensaje al grupo',
                                    style:'float:left;margin-right:20px;',
                                    iconCls:'rck-icon-email',
                                    handler:function(){
                                        _sendMessageToGroup(group);
                                    }
                                }
                            ]
                        },
                        {
                            type:'panel',
                            id:bigPanelMembersId,
                            title:'Miembros',
                            width:'45%',
                            height:490,
                            collapsible:true,
                            style:'float:left;margin-right:50px;',
                            bodyStyle:'width:93.7%;*width:94.7%;_width:94.7%;#width:94.7%;float:left;',
                            items:[
                                {
                                    type:'panel',
                                    id:panelMembersId,
                                    width:'99%',
                                    height:490,
                                    style:'float:left;margin-right:50px;',
                                    bodyStyle:'width:100%;*width:94.7%;_width:94.7%;#width:94.7%;float:left;padding:0;'
                                },
                                {
                                    type:'panel',
                                    id:membersPaginator,
                                    width:'99%',
                                    height:100,
                                    html:'<div class="rck_paginator2" id="'+paginatorMembersId+'"></div>'
                                }
                            ]
                        },
                        {
                            type:'panel',
                            id:panelForoId,
                            title:'Foro Grupo',
                            width:'47%',
                            collapsible:true,
                            bodyStyle:'float:left;width:94%;',
                            style:'float:left;',
                            items:[
                                {
                                    label:'Mensaje',
                                    type:'textarea',
                                    id:txtForoId,
                                    width:'100%',
                                    height:'70px',
                                    change:function(value){
                                        var isDisabled = Rocket.get(btnForoId).getDisabled();
                                        if(value && value!=='' && value.length>0){
                                            Rocket.get(btnForoId).setDisabled(false);
                                        }
                                        else{
                                            Rocket.get(btnForoId).setDisabled(true);
                                        }
                                    }
                                },
                                {
                                    type:'button',
                                    id:btnForoId,
                                    disabled:true,
                                    width:'30%',
                                    style:'float:left;',
                                    value:'Publicar',
                                    handler:function(){
                                        data = {
                                            Message:Rocket.get(txtForoId).val().value,
                                            GrupoId:group.GrupoId,
                                            WallId:group.WallId
                                        };
                                        Rocket.Request({
                                            url: BASE_URL + 'posts/add',
                                            data:data,
                                            success:function(response) {
                                                if(response.success){
                                                    Rocket.get(btnForoId).setDisabled(true);
                                                    threadsManager[group.GrupoId].postAdded = true;
                                                    Rocket.get(txtForoId).set('');
                                                }
                                            }
                                        });
                                    }
                                },
                                {
                                    type:'panel',
                                    id:messagesForoId,
                                    width:'100%',
                                    title:'Mensajes anteriores',
                                    collapsible:true,
                                    bodyStyle:'height:350px;float:left;overflow-y:auto;overflow-x:hidden;width:93.7%;',
                                    style:'float:left;',
                                    html:'<ul id="'+paginatorId+'" class="rck_paginator"></ul><ul id="'+messagesForoId+'_wall" class="messages"></ul>'
                                }
                            ]
                        }
                    ]
                }
            ));
                var memberHtml = "";
                jQuery.each(members,function(k,member){
                    var uid = group.GrupoId+"_"+member.UserId;
//                    var nombre = member.nombre1+' '+member.nombre2+
//                        ' '+member.apellido1+' '+member.apellido2;
                    
                    var nombre = member.nombre1+' '+member.apellido1;
                    
                    if(!member.avatar || member.avatar === 'null' || member.avatar === null) 
                            member.avatar = imageJuanelo;
                        
                    memberHtml = memberHtml+
                        '<div class="member">'+
                        '<img class="member_avatar" src="'+member.avatar+'"/>'+
                        '<ul>'+
                        '<li class="member_name"><a href="#" id="'+uid+'">'+nombre+'</a></li>'+
                        '<li class="member_rol" ">'+member.nombre+'</li>'+
                        '</ul>'+
                        '<div style="margin-left:-5px;" class="member_actions">'+
                        '<a href="#" id="email-'+uid+'"><img src="'+imagePathEmail+'" width="16"/></a>'+
                        '</div>'+
                        '</div>';

                    //seteamos la funcion click en cada nombre de usario con live aun cuando no exista en el DOM
                    jQuery('#'+uid).live('click',function(){
                        var record = new Model(member);
                        userDetail(record);
                    });

                    //seteamos la funcion click en cada email de usario con live aun cuando no exista en el DOM
                    jQuery('#email-'+uid).live('click',function(){
                        _sendMessageToUser(member);
                    });

                    //    Rocket.get(panelMembersId).setHtml('<div class="members">'+memberHtml+'</div>');
                    Rocket.get(panelMembersId).setHtml('<div class="members">'+memberHtml+'</div>');
                });
                _addPaginator4UsersByGroup(group.GrupoId,group.totalMembers);
                title = "";
                
            });
        }
        
        function _sendMessageToUser(record){
            var miembro = record.nombre1+' '+record.nombre2+' '+record.apellido1+' '+record.apellido2;
            if(!winSendMessage){
                winSendMessage = Rocket.Create({
                    type:'panel',
                    id:'winSendMessage',
                    title:'Nuevo Mensaje',
                    width:'40%',
                    isForm:true,
                    modal:true,
                    proxy:{
                        url: BASE_URL+'email/sendToUser'
                    },
                    items:[
                        {
                            type:'label',
                            text:'Para: <strong>'+miembro+'</strong> <span style="font-size:12px;color:#1373bd;">('+record.email+')<span>',
                            id:'lblMessageFor',
                            width:'100%'
                        },
                        {
                            label:'Título',
                            type:'text',
                            id:'txtTitleToSend',
                            name:'Title',
                            width:'100%'
                        },
                        {
                            label:'Mensaje',
                            type:'textarea',
                            name:'Message',
                            id:'txtMessageToSend',
                            width:'100%',
                            height:'70px'
                        },
                        {
                            type:'hidden',
                            id:'hdUserId1',
                            value:record.UserId,
                            name:'UserId'
                        }
                    ],
                    buttons:[
                        {
                            type:'button',
                            id:'btnSendMessage',
                            value:'Enviar',
                            handler:function(){
                                winSendMessage.submit({
                                    success:function(data){
                                        if(data.success){
                                            //formGrupo.resetForm();
                                            Rocket.Create({
                                                type:'dialog',
                                                title:'Operaci\u00F3n exitosa',
                                                typeAlert:'success',
                                                message:data.msg
                                            });
                                            winSendMessage.resetForm();
                                            winSendMessage.close();
                                        }
                                        else{
                                            Rocket.Create({
                                                type:'dialog',
                                                title:data.msg,
                                                typeAlert:'error',
                                                message:_getErrorFromArray(data.errors)
                                            });
                                        }
                                    }
                                });
                            }
                        },
                        {
                            type:'button',
                            id:'btnCancelarMensaje',
                            value:'Cancelar',
                            handler:function(){
                                winSendMessage.resetForm();
                                winSendMessage.close();
                            }
                        }
                    ]
                });
            }
            else{
                Rocket.get('hdUserId1').set(record.UserId);
                Rocket.get('lblMessageFor').set('Para: <strong>'+miembro+'</strong> <span style="font-size:12px;color:#1373bd;">('+record.email+')<span>');
            }
            winSendMessage.show();
        }
        
        function _sendMessageToGroup(record){
            var groupname = record.nombre;
            if(!winSendMessageGroup){
                winSendMessageGroup = Rocket.Create({
                    type:'panel',
                    id:'winSendMessageGroup',
                    title:'Nuevo Mensaje',
                    width:'40%',
                    isForm:true,
                    modal:true,
                    proxy:{
                        url: BASE_URL+'email/sendToGroup'
                    },
                    items:[
                        {
                            type:'label',
                            text:'Para: <strong>'+groupname+'</strong>',
                            id:'lblMessageForGroup',
                            width:'100%'
                        },
                        {
                            label:'Título',
                            type:'text',
                            name:'Title',
                            id:'txtTitleToSendGroup',
                            width:'100%'
                        },
                        {
                            label:'Mensaje',
                            type:'textarea',
                            name:'Message',
                            id:'txtMessageToSendGroup',
                            width:'100%',
                            height:'70px'
                        },
                        {
                            type:'hidden',
                            id:'hdUserId2',
                            value:record.GrupoId,
                            name:'GrupoId'
                        }
                    ],
                    buttons:[
                        {
                            type:'button',
                            id:'btnSendMessageGroup',
                            value:'Enviar',
                            handler:function(){
                                winSendMessageGroup.submit({
                                    success:function(data){
                                        if(data.success){
                                            //formGrupo.resetForm();
                                            Rocket.Create({
                                                type:'dialog',
                                                title:'Operaci\u00F3n exitosa',
                                                typeAlert:'success',
                                                message:data.msg
                                            });
                                            winSendMessageGroup.resetForm();
                                            winSendMessageGroup.close();
                                        }
                                        else{
                                            Rocket.Create({
                                                type:'dialog',
                                                title:data.msg,
                                                typeAlert:'error',
                                                message:'Error al intentar enviar mensajes a los miembros del Grupo'
                                            });
                                        }
                                    }
                                });
                            }
                        },
                        {
                            type:'button',
                            id:'btnCancelarMensajeGroup',
                            value:'Cancelar',
                            handler:function(){
                                winSendMessageGroup.close();
                            }
                        }
                    ]
                });
            }
            else{
                Rocket.get('hdUserId2').set(record.GrupoId);
                Rocket.get('lblMessageForGroup').set('Para: <strong>'+groupname+'</strong>');
            }
            winSendMessageGroup.show();
        }
        
        var detailUserHtml = $("#detailUser").html();
        $("#detailUser").html('');

        winDetail = Rocket.Create({
            type:'panel',
            id: 'winDetail',
            width:'80%',
            height:500,
            title:'Detalle Usuario',
            modal:true,
            items:[
                {
                    type:'panel',
                    id: 'winUser',
                    width:'100%',
                    height:500,
                    renderTo:'detailUser',
                    html:detailUserHtml,
                    style:'background-color:#FFFFFF;padding:5px;border:1px solid #949494;'
                }
            ],
            buttons:[
                {
                    type:'button',
                    id:'close',
                    value:'Cerrar',
                    handler:function(){
                        winDetail.close();
                    }
                }
            ]
        });
        $(".lnkActivity").live('click',function(){
            $(this).parent().next().toggle('slow');
        });
        _getGroups();
    });
</script>
<?php echo utf8_decode($module_banner);?>
<ul class='ul_page'></ul>

<div id="detailUser" style="display:none;">
    <div class="dLeft">
        <img id="imgAvatar"/>
        <ul>
            <li><span class="titulo_nice" id="liNombre"></span></li>
            <li><label>Rut: </label><span id="liRut"></span></li>
            <li><label>Sexo: </label><span id="liSexo"></span></li>
            <li><label>Fecha Nac.: </label><span id="liFechaNacimiento"></span></li>
            <li><label>Oficio: </label><span id="liOficio"></span></li>
            <li class="li_title">datos de contacto</li>
            <li><label>Email: </label><span id="liEmail"></span></li>
            <li><label>Teléfono móvil: </label><span id="liFonoMovil"></span></li>
            <li><label>Teléfono fijo: </label><span id="liFonoFijo"></span></li>
            <li><label>Dirección: </label><span id="liDireccion"></span></li>
            <li class="li_title">datos ministeriales</li>
            <li id="LiEncuentros"></li>

        </ul>
    </div>
    <div class="dRight">
        <div>
            <ul>
                <li >
                    <label><a href="javascript:void(0);" class="lnkActivity titulo_nice">Participa actualmente como</a></label>
                    <ul class="ulDetail" id="ulCurrentp">
                    </ul>
                </li>
                <li><hr></li>
                <li >
                    <label><a href="javascript:void(0);" class="lnkActivity titulo_nice">Participará como</a></label>
                    <ul class="ulDetail" id="ulCurrentf">



                    </ul>
                </li>
                <li><hr></li>
                <li >
                    <label><a href="javascript:void(0);" class="lnkActivity titulo_nice">ah Participado como</a></label>
                    <ul class="ulDetail" id="ulCurrentPast">
                    </ul>
                </li>
            </ul>
        </div>
        <ul>
            <li class="ulGen">
                <label><a href="javascript:void(0);" class="lnkActivity titulo_nice">genealogía</a></label>
                <ul class="ulDetail" id="ulCurrents">
                </ul>
            </li>
        </ul>
    </div>
</div>
